/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2021-01-20
 * Time: 18:09
 */
#include "XmlWriter.h"

XmlWriter::XmlWriter()
{
    WriteXml();
}

void XmlWriter::WriteXml()
{

    QFile file(QCoreApplication::applicationDirPath() + R"(/../../../config/test.xml)");
    int ret = file.open(QFile::WriteOnly | QFile::Text | QFile::Truncate);
    QXmlStreamWriter stream(&file);
    /*[] 自动添加空格 */
    stream.setAutoFormatting(true);
    /*[] 设置缩进格数 */
    stream.setAutoFormattingIndent(4);

    stream.writeStartDocument();
    stream.writeEndDocument();
    stream.writeStartElement("test");
    stream.writeAttribute("test", "a");
    for(int i = 0;i< 10;++i){
        stream.writeStartElement("param");
        stream.writeAttribute("isRead","no");
        stream.writeEndElement();
        stream.setAutoFormatting(false);
        /*[NOTE] 2021-1-20 loong: writeTextElement不应该在添加属性Attribute*/
        stream.writeTextElement("param","test");
        stream.setAutoFormatting(true );
    }
    stream.writeEndElement();

    stream.writeEndElement();
    stream.writeEndDocument();
}
